package fr.mywiki.business.wiki.render.filter;

import org.jdom.Element;
import org.radeox.filter.CacheFilter;
import org.radeox.filter.context.FilterContext;
import org.radeox.filter.regex.LocaleRegexTokenFilter;
import org.radeox.regex.MatchResult;

import fr.mywiki.business.xml.XmlManager;

/**
 * Implements the precode filter.
 * 
 * Transforms a set of lines beginning by two spaces and no * nor - into :
 * 
 * <pre class="code">
 *     ...
 * </pre>
 * 
 * 
 * @author tlombard
 */
public class PreCodeFilter extends LocaleRegexTokenFilter implements
		CacheFilter {

	protected String getLocaleKey() {
		return "filter.precode";
	}

	public void handleMatch(StringBuffer buffer, MatchResult matchResult,
			FilterContext context) {
		String pattern = matchResult.group(0);
		
		Element pre = new Element("pre");
		pre.addAttribute("class","code");
		pre.setText(pattern);
		
		buffer.append(XmlManager.XmlToString(pre));
	}
}
